package com.jhws.business.im.api;

import com.jhws.common.base.bo.JsonRespData;
import com.jhws.business.im.bo.IMDataUpdateModule;
import com.jhws.business.im.bo.IMOfflineMsg;
import com.jhws.business.im.service.IMService;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("v2/IM")
public class imAPIV2 {
    @Resource
    private IMService imService;

    @Resource
    private DataUpdateService dataUpdateService;

    @RequestMapping("anon/offlineMessage")
    @ResponseBody
    public JsonRespData sipOfflineMessage(IMOfflineMsg msg) throws Exception{
        Long timeStamp = System.currentTimeMillis();
        msg.setTimeStamp(timeStamp);
        imService.saveSipOfflineMsg(msg);
        dataUpdateService.pushAndUpdate(timeStamp, IMDataUpdateModule.MSG_INSTANT,msg.getToUser(),true,true,"您有新的短消息",msg.getMessage());
        return new JsonRespData("",1,"");
    }
}
